package com.xiaomi.shop.utils;

import java.io.File;
import java.util.UUID;

/**
 * @ClassName 陈欣月
 * @Descripttion TODO
 * @Author cxy
 * @Date 2021/10/15 11:41
 * @Version 1.0
 **/
public class FileUtils {
    /**
     * 获取文件的类型
     * @param filename
     * @return
     */
    public static String getFileType(String filename){
        //获取  .最后出现的位置
        int index = filename.lastIndexOf(".");
        String str = filename.substring(index);
        return str;
    }

    /**
     * 生成文件名
     * @param context
     * @return
     */
    public static String getRealName(String context){
        //name="myfile";filename = abc.jpg
        int index = context.lastIndexOf("=");
        String fileName = context.substring(index+1,context.length());
        return  fileName;
    }

    /**
     * 借助uuid生成文件名
     * @return
     */
        public static String getUUIDfileName(){
            UUID uuid = UUID.randomUUID();
            String str = uuid.toString().replace("-","");
            return str;

    }

    public static void main(String[] args) {
        /**
         * 9271f2f7461d4005903b6958d56a8837.jpg
         * 1de739cf581148aca08dd7c77e18b839.jpg
         * 1fdce73442a7454da4c7379a7d3ebbec.jpg
         */
        String  saveFileName= FileUtils.getUUIDfileName()+FileUtils.getFileType("zhuhe.jpg");
        System.out.println(saveFileName);
        System.out.println("--------------");
        System.out.println(File.separator);
    }
}
